package cn.tedu.medicalpath.medicine.controller;

import cn.tedu.medicalpath.base.response.JsonResult;
import cn.tedu.medicalpath.base.response.PageData;
import cn.tedu.medicalpath.medicine.pojo.dto.MedicineQuery;
import cn.tedu.medicalpath.medicine.pojo.vo.MedicineVO;
import cn.tedu.medicalpath.medicine.service.MedicineService;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author WangPeiao
 * @date 2024/12/12\
 * @apiNote
 */
@Slf4j
@RestController
@RequestMapping("v1/medicine")
public class MedicineController {
    @Autowired
    MedicineService medicineService;

    @ApiModelProperty(value = "查询药品信息")
    @PostMapping("select")
    public JsonResult select(MedicineQuery medicineQuery){
        log.debug("开始处理【查询药品信息】的请求，参数：{}",medicineQuery);
        PageData data= medicineService.selectMedicine(medicineQuery);
        return JsonResult.success(data);
    }


                                                                                                                       
    /*导出表格*/
    @ApiModelProperty(value = "导出表格")
    @GetMapping("export")
    public JsonResult export(MedicineQuery medicineQuery){
        log.debug("开始处理【导出表格】的请求，参数：{}",medicineQuery);
        List<MedicineVO> data= medicineService.export(medicineQuery);
        return JsonResult.success(data);
    }

    @ApiModelProperty(value = "根据id查询药品")
    @GetMapping("/getMedicine/{medicineId}")
    public JsonResult getMedicineById(@PathVariable("medicineId") Long id){
        log.debug("开始处理【根据id查询药品】的请求，入参：{}",id);
        MedicineVO medicineVO = medicineService.getMedicineById(id);
        log.debug("【根据id查询药品】成功，入参：{}，出参：{}",id,medicineVO);
        return JsonResult.success(medicineVO);
    }

}
